testsuite: Improve GdkCursor coverage
authorMatthias Clasen <mclasen@redhat.com>
Thu, 5 Nov 2020 04:34:36 +0000 (23:34 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 5 Nov 2020 04:36:09 +0000 (23:36 -0500)
testsuite/gdk/cursor.c [new file with mode: 0644]
testsuite/gdk/meson.build

diff --git a/testsuite/gdk/cursor.c b/testsuite/gdk/cursor.c
new file mode 100644 (file)
index 0000000..546f73b
--- /dev/null
@@ -0,0 +1,69 @@
+#include <gtk/gtk.h>
+#include <cairo-gobject.h>
+
+static void
+test_cursor_named (void)
+{
+  GdkCursor *cursor;
+
+  cursor = gdk_cursor_new_from_name ("default", NULL);
+
+  g_assert_cmpstr (gdk_cursor_get_name (cursor), ==, "default");
+  g_assert_null (gdk_cursor_get_fallback (cursor));
+  g_assert_cmpint (gdk_cursor_get_hotspot_x (cursor), ==, 0);
+  g_assert_cmpint (gdk_cursor_get_hotspot_y (cursor), ==, 0);
+  g_assert_null (gdk_cursor_get_texture (cursor));
+
+  g_object_unref (cursor);
+}
+
+static void
+test_cursor_texture (void)
+{
+  GdkPixbuf *pixbuf;
+  GdkTexture *texture;
+  GdkCursor *cursor;
+
+  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 32, 32);
+  texture = gdk_texture_new_for_pixbuf (pixbuf);
+  cursor = gdk_cursor_new_from_texture (texture, 1, 2, NULL);
+
+  g_assert_null (gdk_cursor_get_name (cursor));
+  g_assert_null (gdk_cursor_get_fallback (cursor));
+  g_assert_cmpint (gdk_cursor_get_hotspot_x (cursor), ==, 1);
+  g_assert_cmpint (gdk_cursor_get_hotspot_y (cursor), ==, 2);
+  g_assert_true (gdk_cursor_get_texture (cursor) == texture);
+
+  g_object_unref (cursor);
+  g_object_unref (texture);
+  g_object_unref (pixbuf);
+}
+
+static void
+test_cursor_fallback (void)
+{
+  GdkCursor *fallback;
+  GdkCursor *cursor;
+
+  fallback = gdk_cursor_new_from_name ("default", NULL);
+  cursor = gdk_cursor_new_from_name ("text", fallback);
+
+  g_assert_true (gdk_cursor_get_fallback (cursor) == fallback);
+
+  g_object_unref (cursor);
+  g_object_unref (fallback);
+}
+
+int
+main (int argc, char *argv[])
+{
+  g_test_init (&argc, &argv, NULL);
+
+  gtk_init ();
+
+  g_test_add_func ("/cursor/named", test_cursor_named);
+  g_test_add_func ("/cursor/texture", test_cursor_texture);
+  g_test_add_func ("/cursor/fallback", test_cursor_fallback);
+
+  return g_test_run ();
+}
index c62c9319051312e7d1fb9e45235ba1bd6eafc0ed..cc3125de37c71a8b442fa28d914acdc56c96b636 100644 (file)
@@ -5,6 +5,7 @@ tests = [
   'array',
   'cairo',
   'clipboard',
+  'cursor',
   'display',
   'displaymanager',
   'encoding',